#include "Customer.hh"
#include <algorithm>

namespace mini_bank {

    Customer::Customer(const std::string& name,
                    const std::string& savingsId,
                    const std::string& checkingId,
                    double savingsInitial,
                    double checkingInitial)
        : name(name),
        savings(std::make_unique<SavingsAccount>(savingsId, name, savingsInitial)),
        checking(std::make_unique<CheckingAccount>(checkingId, name, checkingInitial)) 
    {}  
std::string Customer::getName() const { return name; }
Account*    Customer::getSavings() const { return savings.get(); }
Account*    Customer::getChecking() const { return checking.get(); }

std::vector<Transaction> Customer::getAllTransactions() const {
    auto txs = savings->getTransactions();
    auto cks = checking->getTransactions();
    txs.insert(txs.end(), cks.begin(), cks.end());
    std::sort(txs.begin(), txs.end(),
        [](const Transaction& a, const Transaction& b) {
            return a.getTimestamp() < b.getTimestamp();
        });
    return txs;
}

} // namespace mini_bank
